package com.zto.tx.service.impl;

import com.zto.tx.dao.OrderDao;
import com.zto.tx.service.OrderService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2020-12-23 22:49
 **/
@Service
public class OrderServiceImpl implements OrderService, ApplicationContextAware {
    private ApplicationContext applicationContext;


    @Override
    public String query(String name) {
        if ("A".equals(name)) {
            OrderDao orderDao = (OrderDao) applicationContext.getBean("orderDaoImplA");
            orderDao.query("A");

        } else if ("B".equals(name)) {
            OrderDao orderDao = (OrderDao) applicationContext.getBean("orderDaoImplB");
            orderDao.query("B");

        }
        return "service";
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
